package com.algorithmicTest1;

import java.util.Arrays;
import java.util.Comparator;

public class AlgorithmProblems {
    public static void main(String[] args) {
        //创建4个女朋友的对象：
        GirlFriend gf1 = new GirlFriend("lihua", 20, 1.80);
        GirlFriend gf2 = new GirlFriend("zaaohda", 19, 1.74);
        GirlFriend gf3 = new GirlFriend("chenfeiyu", 28, 1.91);
        GirlFriend gf4 = new GirlFriend("xiaoli", 171, 1.68);

        //定义一个数组将对象存入进去：
        GirlFriend[] arr = {gf1, gf2, gf3, gf4};

        //比较字符串：
        Arrays.sort(arr, ( o1,  o2) ->{
                int temp = Integer.compare(o1.getAge(), o2.getAge());
                temp = temp == 0 ? Double.compare(o1.getHeight(), o2.getHeight()) : temp;
                temp = temp == 0 ? o1.getName().compareTo(o2.getName()) : temp;
                return temp;
            }
        );

        System.out.println(Arrays.toString(arr));
    }
}
